<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <title>费用表</title>
    <script src="../../../static/kaige/js/szload.js"></script>
    <style>
        .layui-table-cell {
            height: auto !important;
        }
    </style>
</head>

<body>
<div class="kaige-body">
    <table class="layui-table" id="pageTable" lay-filter="pageTable" lay-size="sm"></table>
    <input type="hidden" name="keywordsCache" value="{}"/>
</div>

<script src="/../../../../pc/static/lib/jquery-3.6.0.min.js"></script>
<script>
    let jq = jQuery.noConflict();
    load_init_js([
        szoapcpath + '/static/kaige/js/date.js',
        szoapcpath + '/static/kaige/js/search.js',
        szoapcpath + '/static/kaige/js/xm-select.js'
    ], function () {
        layui.config({
            base: szoapcpath + '/static/kaige/layuiextend/',
            version: Date.now(),
        }).use(['element', 'table', 'form', 'layer', 'kaige', 'glfiles', 'lvybtpl', 'laydate'], function () {
            var element = layui.element,
                layer = layui.layer,
                table = layui.table,
                form = layui.form,
                glfiles = layui.glfiles,
                lvybtpl = layui.lvybtpl,
                laydate = layui.laydate,
                kaige = layui.kaige
            $ = layui.$;

            window.kaige_page = {
                logout_url: '/index/logout',
                welcome: './pages/welcome.html',
                menus: [],
                leftmenu: [],
            };
            window.pagedict = parent.window.kaige_page.dict || {};

            form.render();

            //系统默认图片
            window.default_image = szoapcpath + "/static/img/default.png";
            //查看图片
            window.viewImage = function (imgUrl) {
                kaige.viewimage({maxwidth: 600, maxheight: 600, url: imgUrl});
            }

            kaige.table({
                elem: '#pageTable',
                url: "/crm.consume/index",
                id: 'pageTable',
                toolbar: '#dtoolbar',
                defaultToolbar: ['filter'],
                cols: [[
                    {field: 'id', title: '', align: 'center'},
                    {field: 'customer_id_name', title: '客户ID', align: 'center'},
                    {field: 'consume_date', title: '消费日期', align: 'center'},
                    {field: 'consume_type', title: '消费方式', align: 'center', templet: "#consume_type_name"},
                    {field: 'money', title: '消费金额', align: 'center'},
                    {field: 'files_id', title: '附件', align: 'center', templet: '#tupian'},
                    {field: 'create_user_name', title: '创建人', align: 'center'},
                    {field: 'create_time', title: '创建时间', align: 'center'},
                    {title: '操作', toolbar: '#dtrbar', align: 'center', width: 150, fixed: 'right'}
                ]]
            });

            //列表-监听表头工具栏事件dtoolbar
            table.on('toolbar(pageTable)', function (obj) {
                switch (obj.event) {
                    case 'btn-add':
                        btnadd();
                        break;
                }
            });

            //列表-监听单元格行工具事件dtrbar
            table.on('tool(pageTable)', function (obj) {
                var that = this;
                var data = obj.data;
                switch (obj.event) {
                    case 'edit':
                        baredit(data);
                        break;
                    case 'del':
                        bardel(data);
                        break;
                }
            });

            //添加
            function btnadd() {
                kaige.form({
                    url: "/crm.consume/add",
                    data: {},
                    id: 'kaige',
                    area: ['750px', '450px'],
                    title: '<i class="layui-icon layui-icon-add-circle"></i> 添加 - 费用表',
                    tablelayid: 'pageTable',
                    overflow: false,
                    encode: 1,
                    callbefore: function (layero, index) {
                        lvybtpl.xmSelect({
                            url: '/select/Customer'
                            , id: 'customer_id'
                            , getData: {automatch: 1}
                            , values: []
                        });
                        laydate.render({
                            elem: '#consume_date'
                            , type: 'date'
                        });
                    },
                    postbefore: function (updata) {
                        updata.files_id = updata.form_files_id;
                        delete updata.form_files_id;
                        return updata;
                    },
                    getdata: function (res) {
                        var data = (res && res.data && res.data.fi) ? res.data.fi : null;
                        glfiles.form({
                            id: 'form',
                            is_edit: true,
                            data: data
                        });
                    }
                });
            }

            //编辑
            function baredit(d) {
                kaige.form({
                    url: "/crm.consume/edit",
                    data: {id: d.id},
                    id: 'kaige',
                    area: ['750px', '450px'],
                    title: '<i class="layui-icon layui-icon-edit"></i> 编辑 - 费用表',
                    tablelayid: 'pageTable',
                    overflow: false,
                    encode: 1,
                    callbefore: function (layero, index) {
                        lvybtpl.xmSelect({
                            url: '/select/Customer'
                            , id: 'customer_id'
                            , getData: {automatch: 1}
                            , values: [d.customer_id]
                        });
                        laydate.render({
                            elem: '#consume_date'
                            , type: 'date'
                        });
                    },
                    postbefore: function (updata) {
                        updata.files_id = updata.form_files_id;
                        delete updata.form_files_id;
                        return updata;
                    },
                    getdata: function (res) {
                        var data = (res && res.data && res.data.fi) ? res.data.fi : null;
                        glfiles.form({
                            id: 'form',
                            is_edit: true,
                            data: data
                        });
                    }
                });
            }

            //删除
            function bardel(d) {
                layer.confirm('您确定删除吗？', {
                    title: '<i class="layui-icon layui-icon-delete"></i> 删除确认',
                    btn: ['确认', '取消']
                }, function () {
                    $.post("/crm.consume/del", {id: d.id}, function (res) {
                        res.status && table.reload('pageTable');
                        layer.msg(res.msg);
                    });
                });
            };

        });
    });
</script>
<script type="text/html" id="dtrbar">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-xs" lay-event="edit" title="编辑"><i class="layui-icon layui-icon-edit"></i>
        </button>
        <button class="layui-btn layui-btn-xs" lay-event="del" title="删除"><i class="layui-icon layui-icon-delete"></i>
        </button>
    </div>
</script>
<script type="text/html" id="tupian">
    <div class="userinfotitle">
        <div class="uif-avatar">
            <a href="javascript:void(0);" onclick="viewImage('{{ d.files_id }}')">
                <img src="{{ d.files_id }}" class="list_avatar1" alt="" width="50px" height="50px"/>
            </a>
        </div>
    </div>
</script>
<script type="text/html" id="dtoolbar">
    <div class="layui-btn-container layui-form filter-form" lay-filter="searchform">
        <div class="layui-btn-group">
            <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-add" style="margin-top:2px;"><i
                    class="layui-icon layui-icon-add-circle"></i> 添加
            </button>
        </div>
    </div>
</script>
<script type="text/html" id="consume_type_name">
    {{# for(var ipd in pagedict.consumeType){ }}
    {{# if(d.consume_type ==ipd){ }}
    <span>{{ pagedict.consumeType[ipd] }}</span>
    {{# } }}
    {{# } }}
</script>
<script type="text/html" id="kaige_form_html">
    <form class="layui-form layui-form-pane kaige-body-form" style="padding: 5px;" lay-filter="kaige_form_lay_filter">
        {{# if(d.id){ }}
        <input type="hidden" name="id" value="{{ d.id }}"/>
        {{# } }}
        <div class="layui-form-item">
            <label class="layui-form-label">客户ID</label>
            <div class="layui-input-inline">
                <div id="customer_id_select_box"></div>
                <input type="hidden" id="customer_id" value="{{ d.customer_id || '' }}" name="customer_id"
                />
                <input id="customer_id_name" name="customer_id_name" value="{{ d.customer_id_name || '' }}"
                       class="layui-input" type="hidden">
            </div>
            <label class="layui-form-label">消费日期</label>
            <div class="layui-input-inline">
                <input id="consume_date" name="consume_date" value="{{ d.consume_date || '' }}" class="layui-input"
                       type="text" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">消费方式</label>
            <div class="layui-input-inline">
                <select name="consume_type" lay-verify="required">
                    {{# lay.each(pagedict.consumeType,function(index,item){
                    if(index == ''){
                    top.layer.msg('系统字典->跟进类型未配置完成，值不能为空');
                    }
                    }}
                    <option value="{{ index }}" {{ d.consume_type== index ?
                    'selected' :'' }}>{{ item }}</option>
                    {{# }) }}
                </select>
            </div>
            <label class="layui-form-label">消费金额</label>
            <div class="layui-input-inline">
                <input name="money" value="{{ d.money || '' }}" class="layui-input" type="number"
                       lay-verify="required|max:10000">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark" id="remark" rows="3" class="layui-textarea">{{ d.remark || '' }}</textarea>
            </div>

        </div>

        <div class="layui-form-item" id="form_files_gl_html"></div>

        <div class="layui-form-item layui-hide">
            <button class="layui-hide" lay-submit="" id="kaige_form_btn_save" lay-filter="kaige_form_btn_save">保存数据
            </button>
        </div>
    </form>
</script>
</body>

</html>